package tfts

var shred = true

func (f *Fight) DoubleCast(rate int) *Fight {
	f.castRate = rate / 2
	f.multicast = 2
	return f
}

func (f *Fight) TripleCast(rate int) *Fight {
	f.castRate = rate / 3
	f.multicast = 3
	return f
}

// 每秒回蓝
func (f *Fight) MPS(name string, mana int) *Fight {
	NewAction(f).Repeat(1).On(TimeGoE).RestoreMana(name, mana)
	return f
}

func (f *Fight) AP() float64 {
	num := 0
	amp := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().ap * attr.stat().factor / 100
			amp += attr.stat().adAmp * attr.stat().factor / 100
		}
	}
	return float64((num-100)*amp)/100/100 + 1
}

func (f *Fight) ad() float64 {
	num := 0
	amp := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().ad * attr.stat().factor / 100
			amp += attr.stat().adAmp * attr.stat().factor / 100
		}
	}
	if f.lockSpeed() {
		transform := (float64(f.BonusAs()) - 100) * f.transformRate()
		num += int(transform)
	}
	return float64((num-100)*amp)/100/100 + 1
}

// 实际额外攻速
func (f *Fight) as() float64 {
	if f.lockSpeed() {
		return 1.0
	}
	return f.RawAs()
}

// 未被锁攻速的抹除额外攻速
func (f *Fight) RawAs() float64 {
	num := f.BonusAs()
	// 攻速上限为5.0
	if float64(num)*f.speed/100 > 5.0 {
		return 5.000 / f.speed
	}
	return float64(num) / 100
}

func (f *Fight) BonusAs() int {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().as * attr.stat().factor / 100
		}
	}
	return num
}

func (f *Fight) ae() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().ae * attr.stat().factor / 100
		}
	}
	return float64(num)
}

func (f *Fight) strike() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().strike
		}
	}
	return float64(num) / 100
}

func (f *Fight) amp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().amp * attr.stat().factor / 100
		}
	}
	return float64(num) / 100
}

func (f *Fight) atkAmp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().atkAmp * attr.stat().factor / 100
		}
	}
	return float64(num) / 100
}

func (f *Fight) castAmp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().castAmp * attr.stat().factor / 100
		}
	}
	return float64(num) / 100
}

func (f *Fight) uAmp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().unqAmp * attr.stat().factor / 100
		}
	}
	return float64(num) / 100
}

func (f *Fight) critRate() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().critChance * attr.stat().factor / 100
		}
	}
	if num > 100 {
		num = 100
	}
	return float64(num) / 100
}

func (f *Fight) critAmp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().critAmp * attr.stat().factor / 100
		}
	}
	return float64(num) / 100
}

func (f *Fight) skillCrit() bool {
	for _, attr := range f.attrs {
		if attr.valid() {
			if attr.stat().skillCrit {
				return true
			}
		}
	}
	return false
}

func (f *Fight) hitMana() int {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().hitMana * attr.stat().factor / 100
		}
	}
	return num
}

func (f *Fight) manaAmp() float64 {
	num := 1.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().manaAmp > 0 {
			num *= attr.stat().manaAmp * float64(attr.stat().factor) / 100
		}
	}
	return num
}

func (f *Fight) manaShrink() float64 {
	num := 1.00
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().manaShrink > 0 {
			shrink := attr.stat().manaShrink * float64(attr.stat().factor) / 100
			num *= shrink
		}
	}
	return num
}

func (f *Fight) manaDec() int {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().manaDec * attr.stat().factor / 100
		}
	}
	return num
}

func (f *Fight) hp() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += attr.stat().health * attr.stat().factor / 100
		}
	}
	return float64(num)
}

func (f *Fight) ar() int {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += attr.stat().armor * attr.stat().factor / 100
		}
	}
	if shred {
		// 默认被减甲
		return num * 7 / 10
	}
	return num
}

func (f *Fight) regen() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() {
			num += attr.stat().regen * float64(attr.stat().factor/100)
		}
	}
	return num
}

func (f *Fight) taken() float64 {
	num := 1.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() && attr.stat().dmgTaken > 0 {
			//num *= float64(attr.stat().dmgTaken*attr.stat().factor) / 100 / 100
			tmp1 := attr.stat().dmgTaken
			tmp2 := attr.stat().factor
			num *= float64(tmp1*tmp2) / 100 / 100
		}
	}
	return num
}

func (f *Fight) steal() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += float64(attr.stat().omnivamp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) hpAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += float64(attr.stat().healthAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) rcvAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += float64(attr.stat().recoverAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) shdAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += float64(attr.stat().shieldAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) hlAmp() float64 {
	num := 0.0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += float64(attr.stat().healAmp*attr.stat().factor/100) / 100
		}
	}
	return num
}

func (f *Fight) hit() float64 {
	num := 0
	for _, attr := range f.attrs {
		if attr.valid() && attr.stat().isFighter() {
			num += attr.stat().hitRecover * attr.stat().factor / 100
		}
	}
	return float64(num)
}
